<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>打印供应商付款申请单</title>
    <link rel="shortcut icon" href="/web/static/src/img/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" href="/web/static/src/css/full.css">
    <link rel="stylesheet" href="/web/static/lib/fontawesome/css/font-awesome.css">
    <link rel="stylesheet" href="/web/static/lib/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="/web/static/src/css/base.css">

    <script language="javascript" src="/lodop/static/lib/lodop6/LodopFuncs.js?v=6.1.0.0"></script>
    <script language="javascript" src="/lodop/static/src/js/mathlibrary.js"></script>

    <style type="text/css" id="style">
        body{padding: 10px; font-size: 10pt;
            overflow:scroll;
        }

        @media print
        {
            .print-hide {display:none}
        }

        .td_inline {
            display:block;
            overflow:hidden;
            white-space:nowrap;
            text-overflow:ellipsis;
            width: 370pt;
        }

        .nowrap{
            white-space:nowrap;
        }

        .curPre {

        }

        .table thead tr td{font-weight: bold; font-size: 11pt; }

        h4{margin: 0px;  padding: 0px;font-size: 14pt}

        h5{
            font-size:11pt; font-family:'黑体'; font-weight: bold; margin: 0px;  padding: 0px;
        }

        div{font-size: 10pt}

        span.foot_sign{border-bottom: 1px solid #ddd}

        .table tbody tr td{border-top: 1px solid #ddd;}
        .table tbody tr:last-child td{border-top: 1px solid #ddd;}
        .table tbody tr.memo td {padding:0px; border-top:0px }

        td{font-size:10pt}

        .font-middle{
            font-size: 12pt;
        }

        .page_head{
            padding-bottom: 20px;
        }

        .bottom-line{
            border-bottom:1px solid #DDD;
        }


    </style>
</head>

<body>
    <object  id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>
        <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0></embed>
    </object>

    <!-- lodop 控制脚本 -->
    <div class="controls controls-row print-hide">
        <script>
            function CheckIsInstall() {
                try{
                    window.LODOP = getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
                    //if ((LODOP!=null)&&(typeof(LODOP.VERSION)!="undefined")) alert("本机已成功安装过Lodop控件!\n  版本号:"+LODOP.VERSION);
                    return true;
                }catch(err){
                    //alert("Error:本机打印控件未安装或需要升级!");
                }
            };

            function print_preview(){
                LODOP.PRINT_INIT("供应商付款申请单");
                LODOP.ADD_PRINT_HTM(0,0,"100%","100%", '<body>' +
                        '<link rel="stylesheet" type="text/css" href="/resources/bootstrap/css/bootstrap.min.css">'+
                        document.documentElement.innerHTML +
                        '</body>');
                LODOP.PREVIEW();
            };
        </script>

        注: 打印A4纸按Ctrl+P键，或者菜单上面选择文件->打印，文件->页面设置里面可以去除页眉页脚

    </div>

    <br/>

    <!-- 供应商付款申请单表头 -->
    <div id="div-header">
        <table border="0" cellSpacing="0" cellPadding="0" width="100%">
            <tbody>
                <tr>
                    <td align="center" colspan="4">
                        <h4 class="page_head">{{account_invoices[0].partner_id.name}}供应商付款申请单
                            {% if account_invoices[0] and account_invoices[0].invoice_line and account_invoices[0].invoice_line[0].purchase_line_id %}
                            （基于采购单)
                            {% endif %}
                            {% if  account_invoices[0] and account_invoices[0].invoice_line and account_invoices[0].invoice_line[0].move_id %}（基于入库单）{% endif %}</h4>
                    </td>
                </tr>
                <tr>
                    <td>
                        <span>编号: </span>
                    </td>
                    <td>
                        日期:
                    
                    </td>
                </tr>
                <tr>
                    <td colspan="4">&nbsp;</td>
                </tr>
                <tr>
                    <td>
                        供应商:
                        {{  account_invoices[0].partner_id.name }}
                         
                    </td>
                    <td >
                        付款方式:
                      
                    </td>
                </tr>

                <tr>
                    <td>
                        关联采购单:
                        {% if  account_invoices|count == 1 and account_invoices.origin %}
                            {{ account_invoices.origin|default('', True)}}
                        {% endif %}
                    </td>
                    <td>
                        总计:{{amount_total|default('', True)}}
                    </td>
                </tr>
            </tbody>
        </table>
    </div>

    <br/>

    <!-- 供应商付款申请单表身 -->
    <div id="div-body">
        <table class="table table-striped" width="100%">
               <thead>
            <tr>
                <td width="60" style="text-align: left;">采购单</td>
                <td>产品名称</td>
                <td>关联销售订单</td>
                <td>是否入库</td>
                <td class="nowrap">采购数量</td>
                <td class="nowrap">单价</td>
                <td class="nowrap" style="text-align: right;">小计</td>
            </tr>
            </thead>
              <tbody>
              {% for account_invoice in account_invoices%}
                {% for data in account_invoice.invoice_line %}
                <tr>
                    <td align="left" >
                     <div>
                        <span>
                                {% if data.purchase_line_id %}
                                    {% set purchase_line_row = _cr.dictfetchone("SELECT order_id FROM purchase_order_line WHERE id=%s" % data.purchase_line_id.id) %}
                                    {% set po_id = purchase_line_row.get('order_id') %}
                                    {% set purchase_order_row = _cr.dictfetchone("SELECT name, so_ids FROM purchase_order WHERE id=%s" % po_id) %}
                                    {% set purchase_name = purchase_order_row.get('name') %}
                                    {% set so_ids = purchase_order_row.get('so_ids') %}
                                {% endif %}
                                {{ purchase_name }}
                        </span>
                    </div>
                    </td>
                    <td>
                        <div>
                            <span>
                                {{data.name}}
                            </span>
                        </div>
                    </td>
                    <td>
                        {% if po_id and so_ids and so_ids[1:-1]%}
                            {% set product_id = data.product_id.id %}
                            {% set sale_product_rows = _cr.dictfetchall("SELECT so.name, (SELECT name FROM res_partner WHERE id=so.partner_id) as partner_name, product_uom_qty FROM sale_order_line sol INNER JOIN sale_order so ON sol.order_id=so.id WHERE so.id IN (%s) AND product_id=%s" % (so_ids[1:-1], product_id)) %}
                            {% if not sale_product_rows %}
                                /无
                            {% endif %}
                            {% for sale_product_row in sale_product_rows %}
                                {% if loop.index > 1 %}
                                <br />
                                {% endif %}
                                {{sale_product_row.get('product_uom_qty')|int}}
                                ({{sale_product_row.get('name')}}
                                {{sale_product_row.get('partner_name')}})
                            {% endfor %}
                        {% endif %}
                    </td>
                    <td>
                        <div>
                            <span>
                                {% if data.purchase_line_id and data.purchase_line_id.product_id.type != 'service' %}
                                    {% set purchase_line_row = _cr.dictfetchone("SELECT product_qty,incomed_qty FROM purchase_order_line WHERE id=%s" % data.purchase_line_id.id) %}
                                    {% set product_qty = purchase_line_row.get('product_qty', 0) %}
                                    {% set product_in_qty = purchase_line_row.get('incomed_qty', 0) %}
                                    {% if product_in_qty == 0 %}
                                       X
                                    {% endif %}
                                    {% if product_qty == product_in_qty and product_in_qty != 0%}
                                      √
                                    {% endif %}
                                    {% if product_in_qty > 0 and  product_qty != product_in_qty%}
                                        {{product_in_qty|int}}
                                    {% endif %}
                                {% endif %}
                            </span>
                        </div>
                    </td>

                    <td>
                        <div>
                            <span>
                                {{data.quantity|int}}
                            </span>
                        </div>
                    </td>
                    <td>
                        <div>
                            <span>
                                {{data.price_unit}}
                            </span>
                        </div>
                    </td>
                    <td style="text-align: right;">
                        {{data.price_subtotal}}
                    </td>

                    </tr>
                    {% endfor %}
                   {% endfor %}
                 <tr>
                    <td colspan="2">
                    </td>
                    <td colspan="5" style="text-align: right;border-top: 1px solid #ddd;">
                        {% if amount_total %}
                                                                        合计：￥{{ amount_total }}
                        {% endif %}
                    </td>
                </tr>
            </tbody>
        </table>

        备注：
        <table class="table table-striped" width="100%">
            {%if account_invoices|count == 1 and account_invoices[0].name%}
            <tr class="memo">
                <td>
                    {{ account_invoices[0].name|default('', True)}}
                </td>
            </tr>
            {% endif %}
        </table>
        &nbsp;<br/>

        操作员：<u>{{account_invoices[0].create_uid.name}}</u>　主管:<u>　　　　　</u>　财务：<u>　　　　　　</u> .

    </div>

    <!-- 供应商付款申请单表尾 -->
    <div id="div-foot">

    </div>

</body>
</html>